package com.da.mybatis.service.impl;

import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.da.mybatis.model.User;
import com.da.mybatis.model.condition.UserCondition;
import com.da.mybatis.mapper.UserMapper;
import com.da.mybatis.service.UserService;

/**
 * Service接口实现
 *
 * @author chenlida
 * @version 1.0.0 2021-05-29
 */
@Service
@Transactional(readOnly = true)
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    private static final Logger logger = LoggerFactory.getLogger(UserService.class);

    @Override
    public IPage<User> findUserByCondition(UserCondition condition) {
        IPage<User> page = condition.buildPage();
        QueryWrapper<User> queryWrapper = condition.buildQueryWrapper(User.class);
        return this.page(page, queryWrapper);
    }

    @Override
    public User getUserById(Integer id) {
        return this.getById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean addUser(User user) {
        return this.save(user);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean updateUser(User user) {
        return this.updateById(user);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean deleteUserById(Integer id) {
        return this.removeById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean deleteUserByIds(List<Integer> idList) {
        return this.removeByIds(idList);
    }
}